//
//  WTMRequest.swift
//  shopAssistant
//
//  Created by 周文杰 on 16/10/12.
//  Copyright © 2016年 com.weitaming. All rights reserved.
//

import UIKit
import Alamofire
import SwiftyJSON

open class WTMResponse: NSObject {

    open var wtmDic: [String:Any]
    open var wtmCode: Int = 0
    open var wtmAlert: AnyObject
    open var wtmList: [Any]
    open var request: Request?
    open var wtmResultArray:Any // for old Mobile APIs Compatible
    
    init(request1: Request?) {
        wtmDic = [:]
        wtmAlert = "" as AnyObject
        wtmList = []
        wtmResultArray = []
        request=request1
        super.init()
    }
    
    init(responseJSON: JSON){
        wtmDic = [:]
        wtmAlert = "" as AnyObject
        wtmList = []
        wtmResultArray = []
        super.init()
        self.analysis(responseJSON)
    }
    
    open func analysis(_ json: JSON) {
        if let jsonString = json["result"].string {
            let jsonObject = JSON.init(parseJSON: jsonString)
            
            if let result =  jsonObject.dictionaryObject {
                self.wtmDic = result
            }else if let result =  jsonObject.arrayObject {
                self.wtmList = result

            }
//            if let data = self.wtmData["data"] as? NSArray {
//                self.wtmList = data
//            }
        }else if let jsonDic = json["result"].dictionaryObject {
            self.wtmDic = jsonDic
        }
        
    }
}
